package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Filedata;
import com.ruoyi.system.service.IFiledataService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文件管理Controller
 *
 * @author ruoyi
 * @date 2023-08-23
 */
@Controller
@RequestMapping("/system/filedata")
public class FiledataController extends BaseController {
    private String prefix = "system/filedata";

    @Autowired
    private IFiledataService filedataService;

    @RequiresPermissions("system:filedata:view")
    @GetMapping()
    public String filedata() {
        return prefix + "/filedata";
    }

    /**
     * 查询文件管理列表
     */
    @RequiresPermissions("system:filedata:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Filedata filedata) {
        startPage();
        List<Filedata> list = filedataService.selectFiledataList(filedata);
        return getDataTable(list);
    }

    /**
     * 导出文件管理列表
     */
    @RequiresPermissions("system:filedata:export")
    @Log(title = "文件管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult<BaseEntity> export(Filedata filedata) {
        List<Filedata> list = filedataService.selectFiledataList(filedata);
        ExcelUtil<Filedata> util = new ExcelUtil<Filedata>(Filedata.class);
        return util.exportExcel(list, "文件管理数据");
    }

    /**
     * 新增文件管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存文件管理
     */
    @RequiresPermissions("system:filedata:add")
    @Log(title = "文件管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult<BaseEntity> addSave(Filedata filedata) {
        return toAjax(filedataService.insertFiledata(filedata));
    }

    /**
     * 修改文件管理
     */
    @RequiresPermissions("system:filedata:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        Filedata filedata = filedataService.selectFiledataById(id);
        mmap.put("filedata", filedata);
        return prefix + "/edit";
    }

    /**
     * 修改保存文件管理
     */
    @RequiresPermissions("system:filedata:edit")
    @Log(title = "文件管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult<BaseEntity> editSave(Filedata filedata) {
        return toAjax(filedataService.updateFiledata(filedata));
    }

    /**
     * 删除文件管理
     */
    @RequiresPermissions("system:filedata:remove")
    @Log(title = "文件管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult<BaseEntity> remove(String ids) {
        return toAjax(filedataService.deleteFiledataByIds(ids));
    }
}
